package com.dailyblue.java.spring.project.smbms.commons.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dailyblue.java.spring.project.smbms.commons.bean.Users;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users> {
    @Select("select id, userCode, userName, gender, birthday, phone, address, userRole, createdBy, creationDate, modifyBy, modifyDate, userstate ,floor(datediff(now(),u.birthday)/365) as 'userage' from smbms_user u where userstate=1 and userCode=#{userCode} and userPassword=md5(#{userPassword})")
    Users login(Users user);

    @Select("select u.id, userCode, userName, gender,if(gender=1,'女','男') as 'userSex', birthday, phone, address, userRole, u.createdBy, u.creationDate, u.modifyBy, u.modifyDate, userstate ,floor(datediff(now(),u.birthday)/365) as 'userage' ,r.id as 'roleId',r.roleName from smbms_user u left join smbms_role r on u.userRole=r.id where userstate=1")
    List<Users> findAllUser();

    List<Users> findUserByNameAndRoleName(@Param("name") String name, @Param("roleId") Integer roleId);
}
